﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using BCDataCenter.BOL;

/// <summary>
/// Summary description for WebServiceNhapHoaDonBanHang
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]


[System.Web.Script.Services.ScriptService()]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WebServiceNhapHoaDonBanHang : System.Web.Services.WebService
{
    string error = "";
    public WebServiceNhapHoaDonBanHang()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    [ScriptMethod()]
    public string[] GetMatHangInfo(string prefixText, int count)
    {
        BWNhapHoaDonBanHang obj = new BWNhapHoaDonBanHang();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable dt = new DataTable();
            dt = obj.dsFilterListMatHang(ref error, prefixText).Tables[0];
            List<string> items = new List<string>(count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["MaTenHang"].ToString(), dt.Rows[i]["MaTenHang"].ToString());
                items.Add(strName);
            }
             
            return items.ToArray();
        }
        catch
        {
            return new string[]{"Không có dữ liệu"};
        }
    }

    [WebMethod]
    [ScriptMethod]
    public string[] GetTTKhachHang(string prefixText, int count)
    {
        BWNhapHoaDonBanHang obj = new BWNhapHoaDonBanHang();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable dt = new DataTable();
            dt = obj.dsFilterListKH(ref error, prefixText).Tables[0];
            List<string> items = new List<string>(count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["MaKH"].ToString(), dt.Rows[i]["MaKH"].ToString());
                items.Add(strName);
            }
            return items.ToArray();
        }
        catch
        {
            return new string[] { "Không có dữ liệu" };
        }
    }
    [WebMethod]
    [ScriptMethod()]
    public string[] GetTuVanVienInfo(string prefixText, int count)
    {
        BWNhapHoaDonBanHang obj = new BWNhapHoaDonBanHang();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable dt = new DataTable();
            dt = obj.dsFilterListTuVanVien(ref error, prefixText).Tables[0];
            List<string> items = new List<string>(count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["MaTenTVV"].ToString(),dt.Rows[i]["MaTenTVV"].ToString());
                items.Add(strName);
            }
            return items.ToArray();
        }
        catch
        {
            return new string[] { "Không có dữ liệu" };
        }
    }

    [WebMethod]
    [ScriptMethod()]
    public string[] GetListLoaiDong(string prefixText, int count, string contextKey)
    {
        BWNhapHoaDonBanHang obj = new BWNhapHoaDonBanHang();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable dt = new DataTable();
            dt = obj.dsFilterListLoaiDong(ref error, prefixText, contextKey).Tables[0];
            List<string> items = new List<string>(count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["LoaiDong"].ToString(), dt.Rows[i]["LoaiDong"].ToString());
                items.Add(strName);
            }
            return items.ToArray();
        }
        catch(Exception ex)
        {
            error = error + ex.Message;
            return new string[] { "Không có dữ liệu" };
        }
    } 

}

